//
//  VisitorLoginView.swift
//  SinaWeibo
//
//  Created by mac on 15/10/6.
//  Copyright © 2015年 cz. All rights reserved.
//

import UIKit

//代理设置 注册,登录 按钮的点击事件
protocol VisitorLoginViewDelegate: NSObjectProtocol{
    //声明方法
    //注册
    func visitorWillRegister()
    //登录
    func visitorWillLogin()
}


class VisitorLoginView: UIView {
    
    //设置代理属性   (防止循环引用)
   weak var visitorDelegate: VisitorLoginViewDelegate?
    
    @IBOutlet weak var smallIcon: UIImageView!
   
    @IBOutlet weak var tipLabel: UILabel!

    @IBOutlet weak var iconView: UIImageView!
    
    //封装设置各个界面的主题
    func setUIInfo(imageName name:String, tipTest:String, isHome:Bool = false){
        iconView.image = UIImage(named: name)
        tipLabel.text = tipTest
        smallIcon.hidden = !isHome
        if isHome{
            startAnimation()
        }
    }
    //设置Home 界面图片转动动画
   private func startAnimation(){
        let anim = CABasicAnimation(keyPath: "transform.rotation")
    anim.repeatCount = MAXFLOAT
    anim.duration = 15
    anim.toValue = 2 * M_PI
    //动画结束后不移除
    anim.removedOnCompletion = false
    //图片添加动画
    smallIcon.layer.addAnimation(anim, forKey: nil)
    }
    
    //注册按钮
    @IBAction func registerAction(sender: AnyObject) {
        //调用代理方法
       visitorDelegate?.visitorWillRegister()
    }
    //登录按钮
    @IBAction func loginAction(sender: AnyObject) {
        visitorDelegate?.visitorWillLogin()
    }
   
}
